unit RepkontrFrm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AppUtils, BaseForm, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinOffice2010Blue, dxSkinscxPCPainter,
  cxPropertiesStore, dxLayoutLookAndFeels, dxLayoutContainer, dxLayoutControl,
  dxSkinOffice2013White, cxStyles, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, cxNavigator, Data.DB, cxDBData, dxLayoutcxEditAdapters,
  dxLayoutControlAdapters, cxContainer, Vcl.Menus, Vcl.StdCtrls, cxButtons,
  cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  FIBDataSet, pFIBDataSet, cxGridLevel, cxClasses, cxGridCustomView, cxGrid;

type
  TRepkontrForm = class(TDezForm)
    grp1: TdxLayoutGroup;
    lc1: TdxLayoutControl;
    lf1: TdxLayoutLookAndFeelList;
    lcf1: TdxLayoutCxLookAndFeel;
    prop1: TcxPropertiesStore;
    grplc1Group1: TdxLayoutGroup;
    grplc1Group2: TdxLayoutGroup;
    v1: TcxGridDBTableView;
    l1: TcxGridLevel;
    grd1: TcxGrid;
    itmlc1Item1: TdxLayoutItem;
    ds_RepKontr: TpFIBDataSet;
    src_Repkontr: TDataSource;
    clv1ARCPLACE: TcxGridDBColumn;
    clv1STRCODE: TcxGridDBColumn;
    clv1OBJNAME: TcxGridDBColumn;
    clv1ROOMNAME: TcxGridDBColumn;
    clv1RACKNAME: TcxGridDBColumn;
    clv1SHELF: TcxGridDBColumn;
    clv1CELL: TcxGridDBColumn;
    clv1NUMBER: TcxGridDBColumn;
    cbb_Kontr: TcxLookupComboBox;
    itmlc1Item11: TdxLayoutItem;
    btn_Refresh: TcxButton;
    itmlc1Item12: TdxLayoutItem;
    btnExcel: TcxButton;
    itmlc1Item13: TdxLayoutItem;
    clv1CNAME: TcxGridDBColumn;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btn_RefreshClick(Sender: TObject);
    procedure btnExcelClick(Sender: TObject);
  private
    { Private declarations }
    procedure OpenDS;
    procedure RefreshDS;
  public
    { Public declarations }
  end;

var
  RepkontrForm: TRepkontrForm;

implementation

uses cmDBUnit;

{$R *.dfm}


procedure TRepkontrForm.btnExcelClick(Sender: TObject);
var
  s: TStrings;
begin
  s:= TStringList.Create;
  try
    s.Add(Self.Caption);
    s.Add(cbb_Kontr.EditText);
    ExportInExcel(grd1,s);
  finally
    FreeAndNil(s);
  end;
end;

procedure TRepkontrForm.btn_RefreshClick(Sender: TObject);
begin
  RefreshDS;
end;

procedure TRepkontrForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:= caFree;
end;

procedure TRepkontrForm.FormCreate(Sender: TObject);
begin
  LoadForm(prop1,Self.Name);
  OpenDS;
end;

procedure TRepkontrForm.OpenDS;
begin
  cmDb.ds_KONTRAGENT.Open;
end;

procedure TRepkontrForm.RefreshDS;
begin
  v1.BeginUpdate(lsimImmediate);
  try
    with ds_RepKontr do begin
      Close;
      ParamByName('kontr').AsVariant:= cbb_Kontr.EditValue;
      Open;
    end;
  finally
    v1.EndUpdate;
    v1.ViewData.Expand(True);
  end;
end;

initialization
 RegisterClass(TRepkontrForm);
end.
